package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据条件查询购物车
     * @param shoppingcart
     */
    ShoppingCart selectShoppingCart(ShoppingCart shoppingcart);

    /**
     * 更新购物车内物品数量
     * @param shoppingcart
     */
    @Update("update shopping_cart set number =#{number} where id=#{id}")
    void updateNumber(ShoppingCart shoppingcart);

    /**
     * 添加购物车
     * @param shoppingcart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingcart);

    /**
     * 查询购物车内的物品
     * @param userId
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> list(Long userId);

    /**
     * 清空购物车
     */
    @Delete("delete from shopping_cart where user_id=#{userId} ")
    void clean(Long userId);

    /**
     * 购物车商品删减
     *
     * @param id
     * @return
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void delete(Long id);
}
